package com.kobe.algorithm.leetcode.case12;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author ：caopengfei
 * @date ：2021/2/23
 */
public class Solution {



    public String intToRoman(int num) {
        Map<Integer,String> prefix= new LinkedHashMap<>();
        StringBuilder stringBuilder = new StringBuilder();
        prefix.put(1000,"M");
        prefix.put(900,"CM");
        prefix.put(500,"D");
        prefix.put(400,"CD");
        prefix.put(100,"C");
        prefix.put(90,"XC");
        prefix.put(50,"L");
        prefix.put(40,"XL");
        prefix.put(10,"X");
        prefix.put(9,"IX");
        prefix.put(5,"V");
        prefix.put(4,"IV");
        prefix.put(1,"I");
        for (int key: prefix.keySet()) {
            while(num >= key){
                stringBuilder.append(prefix.get(key));
                num = num - key;
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.intToRoman(58));
    }
}
